﻿using SIAKAD.Helper;
using SIAKADCORE.Controllers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SIAKAD.Mahasiswas
{
    public partial class Kuisioner : System.Web.UI.Page
    {
        private DataSet lstDropdown;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !Page.IsCallback)
            {
                IsiDropdown();
            }
        }

        
        private void IsiDropdown()
        {
            this.lstDropdown = new DataSet();
            bool isSuccess = KuisionerController.GetListMatakuliah((Session["siakad"] as SIAKADCORE.Models.Login).IdLogin, out this.lstDropdown);

            if (isSuccess)
            {
                foreach (DataRow row in this.lstDropdown.Tables[0].Rows)
                {
                    this.ddlMatakuliah.Items.Add(new ListItem { Text = String.Format("{0} | {1} | {2} | {3} | {4}", row[1], row[2], row[3], row[4], row[5]), Value = row[0].ToString() });
                }
            }
        }

        private void CheckSession()
        {
            if (Session["siakad"] != null && Session["siakad"] is SIAKADCORE.Models.Login)
            {
                if ((Session["siakad"] as SIAKADCORE.Models.Login).UserType != SIAKADCORE.Models.LoginType.Mahasiswa)
                {
                    Response.Redirect(SiteMapHelper.Check((Session["siakad"] as SIAKADCORE.Models.Login)), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    this.litName.Text = MahasiswaController.GetName((Session["siakad"] as SIAKADCORE.Models.Login).IdLogin);
                }
            }
            else
            {
                Response.Redirect("/Login.aspx");
            }
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            CheckSession();
        }

        protected void btSubmit_Click(object sender, EventArgs e)
        {
            if (this.ddlMatakuliah.Items.Count > 0)
            {
                Response.Redirect("KuisionerIsi.aspx?show=" + this.ddlMatakuliah.SelectedValue, false);
                Context.ApplicationInstance.CompleteRequest();
            }
        }
    }
}